// pages/ParkingPayment/kmabacus/pkvfeequeryList/pkvfeequeryList.js


const App = getApp()

//网络请求封装
import Request_post from "../../../../request/Request_post"
import Request_get from "../../../../request/Request_get"

//系统设置项目:(请求地址-在封装中已经引入，这里不需要;   api调用的Appid-partner_app_id;   渠道ID-as_appid)
import config from '../../../../config/config'; 

// 数字保留2位小数
var toDecimalTwo = require("../../../../utils/CustomFunction/DecimalTwo.js")

//引入时间函数 (当月第一天、当天、最后一天)
var dateArray = require("../../../../utils/CustomFunction/getDayFirstNowLast.js")

//引入日期时间：（格式化、反格式化）函数
var formatDate = require("../../../../utils/CustomFunction/dateFormat.js")
var unformatDate = require("../../../../utils/CustomFunction/dateUnFormat.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {

    // Vant: tabbar(当前选中标签的索引,本页面索引 == 1)
    active: 1,

    calendar:config.imageUrl+"calendar.png",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    //获取本月第一天 & 最后一天日期
    const getdateArray = dateArray.getDayFirstNowLast()
    this.setData({
      bdate:getdateArray[0],
      edate:getdateArray[2]
    })


    // 昭通金池定制跳转
    if(App.globalData.miniProgram_appid == 'wx2e4f358a20d4a419'){   //昭通金池小程序：wx2e4f358a20d4a419
      this.setData({tabbartext:'西苑汇'})
    }else{
      this.setData({tabbartext:'返回首页'})
    }


  },

  // tabbar 选中事件 (本页面的：active == 1)
  onChange(event) {
    this.setData({ active: event.detail });
    if(this.data.active == 0){
      wx.redirectTo({
        url:"/SubpkgParkingPay/pages/ParkingPublic/NumberPlate/NumberPlate"
      })
    }else if(this.data.active == 2){
      wx.navigateTo({
        url:"/SubpkgMarketing/pages/Coupon/CopCenter/CopCenter?fromPkvPage=true",
      })
    }
    else if(this.data.active == 3){
      if(App.globalData.miniProgram_appid == 'wx2e4f358a20d4a419'){   //昭通金池小程序：wx2e4f358a20d4a419
        wx.navigateToMiniProgram({
          appId: 'wx54b2f86f6aecfdff',
          path: '/pages/home/dashboard/index',
          success(res) {
            console.log(res)
          }
        })
      }else{
        wx.redirectTo({
          url:App.globalData.homePage,
        })
      }

		}

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  bindbdateChange: function(e) {
    var that = this
		that.setData({
      bdate:unformatDate.DatString(e.detail.value)
    })
    that.requestList()
  },

  bindedateChange: function(e) {
    var that = this
    that.setData({
      edate:unformatDate.DatString(e.detail.value)
    })
    that.requestList()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    Request_get.get(
      config.domainName+config.pkvApi+"/pkvsrv/listmbrpkvtrdrcd",
      {
        openid: App.globalData.wx_openid,
        bdate: that.data.bdate,
        edate: that.data.edate,
      },
      function(res){
        var list = res.return_data
        for(var i in list){
          list[i].pkvfeeamt = toDecimalTwo.toDecimalTwo(res.return_data[i].pkvamt)
        }
        that.setData({
          pkvfeelist:list
        })
        that.pkvdesConver();
        console.log(that.data.pkvfeelist)
      }
    )

    // 回到本页面，将tabbar的图标置位“缴费记录”
    this.setData({ active: 1 });

  },



  // 列表查询方法——被调用
  requestList:function(){
    var that = this
    Request_get.get(
      config.domainName+config.pkvApi+"/pkvsrv/listmbrpkvtrdrcd",
      {
        openid: App.globalData.wx_openid,
        bdate: that.data.bdate,
        edate: that.data.edate
      },
      function(res){
        var list = res.return_data
        for(var i in list){
          list[i].pkvfeeamt = toDecimalTwo.toDecimalTwo(res.return_data[i].pkvamt)
        }
        that.setData({
          pkvfeelist:list
        })
      }
    )
  },



  /** 点击列表-跳转到详情页面 */
  toDetails_Page:function(e){
    // console.log(e)
    let scd = e.currentTarget.dataset.scd
    wx.navigateTo({
      // url: '/pages/ParkingPayment/'+App.globalData.pkvContext+'/pkvfeequeryDetails/pkvfeequeryDetails?scd='+scd,
      url: "/SubpkgParkingPay/pages/ParkingPublic/pkvfeequeryDetails/pkvfeequeryDetails?scd="+scd
    })
  },


  /** 停车场名称对应（被调用） */
 pkvdesConver:function(){
  var pkvfeelist = this.data.pkvfeelist
  for(var i in pkvfeelist){
    if(pkvfeelist[i].pkvcnnno == 'ZTJC_HK'){
      pkvfeelist[i].pkvcnndes = '金池地下停车场'
    }else if(pkvfeelist[i].pkvcnnno == 'ZTJC_YF'){
      pkvfeelist[i].pkvcnndes = '金池机械车库'
    }else if(pkvfeelist[i].pkvcnnno == 'XZNM_HK'){
      pkvfeelist[i].pkvcnndes = '学庄农贸停车场'
    }
    this.setData({
      pkvfeelist
    })
  }
	
 },
	

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})